home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 2 / BBS in a box - Trilogy II.iso / Files / Game / F-G / Glypha II 1.1 ƒ / Glypha II 1.1 Source Code ƒ / Code ƒ / J-Glypha.p < prev    next >
Encoding:
Text File  |  1991-05-23  |  10.8 KB  |  368 lines  |  [TEXT/PJMM]

  1. program Glypha;    {Glypha II ©1991 John Calhoun}
  2. {$I-}
  3.  
  4.     uses
  5.         Sound, Palettes, Globals, GameUtils, Enemies, GlyphaGuts, Initialize, Menus;
  6.  
  7.     var
  8.         code, index, theMenu, theItem, chCode, flashes: integer;
  9.         ch: char;
  10.         mResult, tickWait, dummyLong: LongInt;
  11.         whichWindow: WindowPtr;
  12.         tempRect: Rect;
  13.         theInput: TEHandle;
  14.         mousePt: Point;
  15.         err: OSErr;
  16.         eventHappened: Boolean;
  17.  
  18. {===================================}
  19.  
  20.     procedure CheckTheMouse;
  21.         var
  22.             screenPos: Integer;
  23.  
  24. {--------------------}
  25.  
  26.         procedure HorizontalMouse;
  27.             const
  28.                 MBState = $172;
  29.                 MTemp = $828;
  30.                 RawMouse = $82C;
  31.                 Mouse = $830;
  32.                 CrsrNew = $8CE;
  33.                 CrsrCouple = $8CF;
  34.                 Couple = $FF;
  35.                 Uncouple = $00;
  36.             var
  37.                 center: Point;
  38.                 lowGlob: Integer;
  39.                 lowMem: Ptr;
  40.                 pointPtr: ^Point;
  41.         begin
  42.             SetPt(center, mousePt.h, 240);
  43.             lowMem := Pointer(rawMouse);
  44.             pointPtr := @lowMem^;
  45.             pointPtr^ := center;
  46.             lowMem := Pointer(MTemp);
  47.             pointPtr := @lowMem^;
  48.             pointPtr^ := center;
  49.             lowMem := Pointer(CrsrNew);
  50.             lowMem^ := $FFFF;
  51.         end;
  52.  
  53. {--------------------}
  54.  
  55.     begin
  56.         GetMouse(mousePt);
  57.         HorizontalMouse;
  58.         screenPos := (mousePt.h - 320 - rightOffset) div 8;
  59.         if (screenPos > 16) then
  60.             screenPos := 16;
  61.         if (screenPos < -16) then
  62.             screenPos := -16;
  63.  
  64.         with thePlayer do
  65.             begin
  66.                 if (facing = 0) then
  67.                     begin
  68.                         if (screenPos < 0) then
  69.                             facing := 1
  70.                         else
  71.                             begin
  72.                                 if (screenPos > horiVel) then
  73.                                     keyStillDown := TRUE
  74.                                 else
  75.                                     keyStillDown := FALSE;
  76.                             end;
  77.                     end
  78.                 else
  79.                     begin
  80.                         if (screenPos > 0) then
  81.                             facing := 0
  82.                         else
  83.                             begin
  84.                                 if (screenPos < horiVel) then
  85.                                     keyStillDown := TRUE
  86.                                 else
  87.                                     keyStillDown := FALSE;
  88.                             end;
  89.                     end;
  90.             end;
  91.     end;
  92.  
  93. {===================================}
  94.  
  95.     procedure CheckTheKeyboard;
  96.         var
  97.             keyState: KeyMap;
  98.     begin
  99.         keyStillDown := FALSE;
  100.         GetKeys(keyState);
  101.  
  102.         if ((keyState[kLeftKey1]) or (keyState[kLeftKey2])) then
  103.             begin
  104.                 keyStillDown := TRUE;
  105.                 thePlayer.facing := kLeftFace;
  106.             end;
  107.         if ((keyState[kRightKey1]) or (keyState[kRightKey2])) then
  108.             begin
  109.                 keyStillDown := TRUE;
  110.                 thePlayer.facing := kRightFace;
  111.             end;
  112.     end;
  113.  
  114. {===================================}
  115.  
  116.     procedure HandleGameEvent;
  117.         var
  118.             wasPort: GrafPtr;
  119.     begin
  120.         case theEvent.what of
  121.             KeyDown: 
  122.                 begin
  123.                     chCode := BitAnd(theEvent.message, CharCodeMask);
  124.                     if (ODD(theEvent.modifiers div CmdKey)) then
  125.                         begin
  126.                             mResult := MenuKey(CHR(chCode));
  127.                             theMenu := HiWord(mResult);
  128.                             theItem := LoWord(mResult);
  129.                             if (theMenu <> 0) then
  130.                                 Handle_My_Menu(theMenu, theItem, theInput); {Do the menu selection}
  131.                         end
  132.                     else if (keyboardControl) then
  133.                         with thePlayer do
  134.                             case chCode of
  135.                                 kSpaceBar:        {flap}
  136.                                     begin
  137.                                         state := TRUE;
  138.                                     end;
  139.                                 82, 114:                    {refresh}
  140.                                     begin
  141.                                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, nil);
  142.                                         ShowScore;
  143.                                         ShowMortals;
  144.                                         ShowLevel;
  145.                                     end;
  146.                                 70, 102:                    {flush}
  147.                                     begin
  148.                                         GetPort(GrafPtr(wasPort));
  149.                                         SetPort(GrafPtr(mainWndo));
  150.                                         FillRect(mainWndo^.portBits.bounds, black);
  151.                                         SetPort(GrafPtr(wasPort));
  152.                                     end;
  153.  
  154.                                 otherwise
  155.                                     begin
  156.                                     end;
  157.                             end;    {end case chCode of}
  158.                 end;        {end of KeyDown event}
  159.             MouseDown: 
  160.                 begin
  161.                     thePlayer.state := TRUE;
  162.                 end;
  163.             UpDateEvt:                {Update event for a window}
  164.                 begin                        {Handle the update}
  165.                     whichWindow := WindowPtr(theEvent.message); {Get the window the update is for}
  166.                     if (whichWindow = mainWndo) then
  167.                         begin
  168.                             SetPort(GrafPtr(mainWndo));
  169.                             BeginUpdate(mainWndo);     {Set the clipping to the update area}
  170.                             CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, nil);
  171.                             ShowScore;
  172.                             ShowMortals;
  173.                             ShowLevel;
  174.                             EndUpdate(mainWndo);       {Return to normal clipping area}
  175.                             SetPort(GrafPtr(virginCPtr));
  176.                         end;
  177.                 end;
  178.             otherwise
  179.         end;
  180.     end;
  181.  
  182. {===================================}
  183.  
  184. begin
  185.     InitVariables;
  186.     UnloadSeg(@InitVariables);
  187.     tickWait := TickCount;
  188.     theInput := nil;
  189.  
  190.     repeat
  191.  
  192.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, flameRect[0], flameRect[0], srcCopy, nil);
  193.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, flameRect[1], flameRect[0], srcCopy, nil);
  194.         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, flameRect[0], flameRect[1], srcCopy, nil);
  195.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, flameRect[0], flameRect[0], srcCopy, nil);
  196.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, flameRect[1], flameRect[1], srcCopy, nil);
  197.         Delay(4, dummyLong);
  198.         if DoRandom(200) = 0 then
  199.             begin
  200.                 SetPort(GrafPtr(mainWndo));
  201.                 flashes := DoRandom(4) + 1;
  202.                 CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, mainWndo^.portBits, eyeRects[4], eyeRects[4], theEye.dest);
  203.                 DoTheSound('lightning.snd', highPriority);
  204.                 for index := 1 to flashes do
  205.                     StrikeLightning(upperEye);
  206.                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, theEye.dest, theEye.dest, srcCopy, playRgn);
  207.             end;
  208.  
  209.         if (hasWNE) then
  210.             eventHappened := WaitNextEvent(everyEvent, theEvent, sleep, nil)
  211.         else
  212.             begin
  213.                 SystemTask;
  214.                 eventHappened := GetNextEvent(everyEvent, theEvent);
  215.             end;
  216.  
  217.         if (eventHappened) then
  218.             begin
  219.                 code := FindWindow(theEvent.where, whichWindow); {Get which window the event happened in}
  220.                 case theEvent.what of                            {Decide type of event}
  221.                     MouseDown:                                                {Mouse button pressed}
  222.                         begin                                                        {Handle the pressed button}
  223.                             if (code = inMenuBar) then        {See if a menu selection}
  224.                                 begin                                    {Get the menu selection and handle it    }
  225.                                     mResult := MenuSelect(theEvent.Where);                {Do menu selection    }
  226.                                     theMenu := HiWord(mResult);            {Get the menu list number            }
  227.                                     theItem := LoWord(mResult);            {Get the menu list item number    }
  228.                                     Handle_My_Menu(theMenu, theItem, theInput);         {Handle the menu    }
  229.                                 end;                                            {End of inMenuBar                    }
  230.                             if (code = inSysWindow) then                {See if a DA selection        }
  231.                                 SystemClick(theEvent, whichWindow); {Let other programs in        }
  232.                         end;                                                {End of MouseDown            }
  233.                     KeyDown:                                            {Handle key inputs            }
  234.                         begin
  235.                             with theEvent do
  236.                                 begin
  237.                                     chCode := BitAnd(message, CharCodeMask);    {Get character}
  238.                                     ch := CHR(chCode);                    {Change to ASCII}
  239.                                     if (Odd(modifiers div CmdKey)) then        {See if Command key is down}
  240.                                         begin
  241.                                             mResult := MenuKey(ch);           {See if menu selection}
  242.                                             theMenu := HiWord(mResult); {Get the menu list number}
  243.                                             theItem := LoWord(mResult); {Get the menu item number}
  244.                                             if (theMenu <> 0) then        {See if a list was selected}
  245.                                                 Handle_My_Menu(theMenu, theItem, theInput); {Do the menu selection}
  246.                                         end
  247.                                     else
  248.                                         case ch of
  249.                                             'l': 
  250.                                                 begin
  251.                                                     SetPort(GrafPtr(mainWndo));
  252.                                                     for index := 1 to 10 do
  253.                                                         StrikeLightning(DoRandom(4));
  254.                                                 end;
  255.                                             'L': 
  256.                                                 begin
  257.                                                     SetPort(GrafPtr(mainWndo));
  258.                                                     flashes := DoRandom(4) + 1;
  259.                                                     CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, mainWndo^.portBits, eyeRects[4], eyeRects[4], theEye.dest);
  260.                                                     DoTheSound('lightning.snd', highPriority);
  261.                                                     for index := 1 to flashes do
  262.                                                         StrikeLightning(upperEye);
  263.                                                     CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, theEye.dest, theEye.dest, srcCopy, playRgn);
  264.                                                 end;
  265.                                             'm', 'M': 
  266.                                                 DoTheSound('music.snd', highPriority);
  267.                                             otherwise
  268.                                                 begin
  269.                                                 end;
  270.                                         end;
  271.                                 end;                {End for with}
  272.                         end;                        {End for KeyDown,AutoKey}
  273.                     UpDateEvt:                {Update event for a window}
  274.                         begin                        {Handle the update}
  275.                             whichWindow := WindowPtr(theEvent.message); {Get the window the update is for}
  276.                             BeginUpdate(whichWindow);     {Set the clipping to the update area}
  277.                             CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, nil);
  278.                             ShowScore;
  279.                             ShowMortals;
  280.                             ShowLevel;
  281.                             EndUpdate(whichWindow);       {Return to normal clipping area}
  282.                         end;                            {End of UpDateEvt}
  283.                     ActivateEvt:                   {Window activated event}
  284.                         begin                           {Handle the activation}
  285.                             whichWindow := WindowPtr(theEvent.message); {Get the window to be activated}
  286.                             if odd(theEvent.modifiers) then {Make sure it is Activate and not DeActivate}
  287.                                 SelectWindow(whichWindow);    {Activate the window by selecting it}
  288.                         end;                            {End of ActivateEvt}
  289.                     App4Evt: 
  290.                         case BSR(theEvent.message, 24) of    {high byte of message}
  291.                             1:                          {suspendResumeMessage}
  292.                                 if (BitAnd(theEvent.message, suspendResumeBit) = resuming) then
  293.                                     inBackground := FALSE
  294.                                 else
  295.                                     begin
  296.                                         inBackground := TRUE;        {it was a suspend event}
  297.                                         if (chanPtr <> nil) then
  298.                                             err := SndDisposeChannel(chanPtr, TRUE);
  299.                                         chanPtr := nil;
  300.                                     end;
  301.                             otherwise
  302.                                 ;
  303.                         end; {CASE}
  304.                     otherwise
  305.                 end;                              {End of case}
  306.  
  307.                 while (playing) do
  308.                     begin
  309.                         gameCycle := gameCycle + 1;
  310.                         if keyboardControl then
  311.                             CheckTheKeyboard
  312.                         else
  313.                             CheckTheMouse;
  314.                         HideCursor;
  315.                         if (stonesSliding) then
  316.                             SlideTheStones;
  317.                         MoveThePlayer;
  318.                         HandleTheEnemies;
  319.                         UpdateEye;
  320.                         with thePlayer do
  321.                             begin
  322.                                 if ((dest.bottom > handTop - 20) and (dest.left > handLeft) and (not otherState)) then
  323.                                     UpdateTheHand
  324.                                 else if (theHand.state) then
  325.                                     RetractTheHand;
  326.                                 DrawBeasts;
  327.                                 DrawPlayer(dest, oldDest);
  328.                                 oldDest := dest;
  329.                             end;
  330.                         if (deadAndGone) then
  331.                             ExitAMortal;
  332.                         if (onward) then
  333.                             AdvanceALevel;
  334.  
  335.                         repeat
  336.                             if GetOSEvent(everyEvent, theEvent) then
  337.                                 HandleGameEvent;
  338.                         until (not pausing);
  339.  
  340.                         repeat
  341.                         until (TickCount >= tickWait);
  342.                         tickWait := TickCount + gameSpeed;
  343.                     end;
  344.             end;
  345.     until doneFlag;                       {End of the event loop}
  346.  
  347.     HUnlock(Handle(playRgn));
  348.     DisposeRgn(playRgn);
  349.     HUnlock(Handle(obeliskRgn1));
  350.     DisposeRgn(obeliskRgn1);
  351.     HUnlock(Handle(obeliskRgn2));
  352.     DisposeRgn(obeliskRgn2);
  353.     if (chanPtr <> nil) then
  354.         err := SndDisposeChannel(chanPtr, FALSE);
  355.  
  356.     DisposePalette(mainPalette);
  357.  
  358.     DisposeWindow(GrafPtr(mainWndo));
  359.     CloseCPort(objectCPtr);
  360.     DisposPtr(objectCBits);
  361.     CloseCPort(virginCPtr);
  362.     DisposPtr(virginCBits);
  363.     CloseCPort(loadCPtr);
  364.     DisposPtr(loadCBits);
  365.  
  366.     WriteOutScores;
  367.  
  368. end.                                    {End of the program}